package main

import (
	"fmt"
	"math"
)

func main() {
	nums := []int{2, 3, 1, 2, 4, 3}
	target := 7

	res := minSubArrayLen(target, nums)
	fmt.Println(res)
}

// 长度最小的子数组
func minSubArrayLen(target int, nums []int) int {
	l, r := 0, 0
	n := len(nums)
	tmpSum := 0
	resNum := math.MaxInt //没有符合的
	for r < n {
		tmpVal := nums[r]
		tmpSum += tmpVal
		r++
		for tmpSum >= target {
			resNum = min(resNum, r-l)
			tmpSum -= nums[l]
			l++
		}
	}
	if resNum == math.MaxInt {
		resNum = 0
	}
	return resNum
}

func min(v1, v2 int) int {
	if v1 > v2 {
		return v2
	}
	return v1
}

var _ = `
l = 0
r = 0
while l < r && r < num.size(){
	addWindow(num[r])
    r++


}
`

func sliceWindow(nums []int) {
	l, r := 0, 0
	n := len(nums)

	for l < r && r < n {
		//window.add(nums[r])
		// r++
	}
}
